package jdklearn.jdk动态代理;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;

/**
 * create at 2018/10/23
 * author: suveng
 * email: suveng@163.com
 **/
public class Main {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class<?> proxyClass = Proxy.getProxyClass(Hello.class.getClassLoader(), Hello.class);
        Constructor<?> constructor = proxyClass.getConstructor(InvocationHandler.class);
        Object o = constructor.newInstance(new MyInvocation(new HelloImpl()));
        Hello hello= (Hello) o;
        hello.say();


        Hello hello2 = (Hello) Proxy.newProxyInstance(Hello.class.getClassLoader(), new Class[]{Hello.class}, new MyInvocation(new HelloImpl()));
        hello2.say();

    }
}
